//
//  LoadingView.swift
//  Yolan123
//
//  Created by Fenly on 2018/4/26.
//  Copyright © 2018年 Cotte. All rights reserved.
//

import UIKit

class LoadingView: UIView {
    
    var loadingText = UILabel()
    let shadeView = UIView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        loadSubView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        loadSubView()
    }
    
    private func loadSubView() {
        addSubview(loadingText)
        addSubview(shadeView)
    }
    
    func loadUI(loadText: String) {
        self.backgroundColor = UIColor.white
        loadingText.text = loadText
        loadingText.snp.makeConstraints { (make) in
            make.top.left.bottom.right.equalToSuperview()
        }
        shadeView.backgroundColor = UIColor.white
        shadeView.snp.makeConstraints { (make) in
            make.top.left.right.bottom.equalToSuperview()
        }
        
    }
    
    func showLoadingView() {
        UIView.animate(withDuration: 0.8, delay: 0, options: .repeat, animations: {
            self.shadeView.center.x = self.shadeView.center.x + self.shadeView.frame.size.width
            
        }, completion: nil)
    }
    
    func hideLoadingView() {
        self.isHidden = true
    }

}
